-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-115028: Add support for relocatable installations using $ORIGIN in RPATH #131781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…GIN in RPATH This patch adds a new configure option --with-relative-rpath that, when enabled, adds $ORIGIN-based RPATHs to binaries when building Python on Linux. This makes Python installations relocatable so they can be moved to different directories without breaking dynamic library dependencies. Three new variables are introduced to set RPATHs for different components: - PY_RPATH_EXEC: For the Python interpreter binary - PY_RPATH_LIB: For the shared libpython library - PY_RPATH_MOD: For Python extension modules This is a step toward solving the relocatability issues discussed in packaging forums and helps ena
I'm not entirely clear on which problem we're trying to solve here, and I think there are problems in this area we shouldn't try to solve (but instead make sure users have the tools to solve them, which I think they already do). With the exception of libpython.so (which I'll get back to), we shouldn't have any shared library dependencies (as fulfilled by ld.so) within the Python installation, right? The only shared library we build that things explicitly link to is libpython.so. Any dependencies we (optionally) include in our build (libffi, expat, etc) are linked statically into the extension or binary instead, and all extension modules, while .so files, are built without a dependency on any other .so files inside the Python installation. Extension modules are .so's, but we don't (and mustn't!) rely on ld.so to find them. We load them explicitly with libpython.so is a different matter. When building with (There's a side topic about what to do with third-party extension modules that do link against libpython, or third-party .so's that are expected to be used either as plugins in an embedded Python or by extension modules loaded into a statically linked python. Technically that's a problem if they are loaded in a statically linked python, but in practice, I don't think it matters. If it does matter perhaps we could have an empty libpython.so (or one with trampoline functions?) that Python That takes care of all shared libraries in a Python installation, right? Am I forgetting any? So when statically linking, the Python installation itself should be just as relocatable as when fiddling with RPATH. (There are probably many other issues to solve, like all the hardcoded paths in sysconfigdata, but that's not fixed by this PR either.) The other concern seems to be external dependencies: building a Python that uses, for example, a specific version of a shared library that's installed elsewhere. I'm not convinced we should try to solve that in Python itself. It's not specific to how Python is built. It's a property of the larger system you're setting up. Other binaries builtin within such a system have to do the same thing. ELF isn't really set up for this, and it's very easy to end up with a mess of shared libraries loaded from different places. (I know, I worked at Google on their version of this, which involves separate ld.so's and libc's in alternative places, and it still messed up every now and then because of, for example, config files living in /etc despite the install directory of the library being elsewhere.) Moreover, if they're dependencies of extension modules, the building of the extension module can include setting RPATH, without affecting the python binary. ($ORIGIN in that case is relative to the .so.) You can even do that for individual extension modules in the standard library, by editing Modules/Setup. If we try to solve this problem for the Python binary we may just end up creating an attractive nuisance, and then actively hampering other approaches to solving the same problem. For example, this PR adds $prefix/lib to the search path, but someone building a self-contained system like this may need other paths to be added. Or they may want to move the library somewhere else, or move the python binary out of the |
Pablo and I had a chat, and he's convinced me that users don't have the tools to solve the second problem. We need a better way to pass linker flags to extension modules that's separate from passing linker flags to the python binary. I think we agreed that this PR isn't it, though, since it only works for --rpath. |
As a side note, since 3.11, https://docs.python.org/dev/using/configure.html#options-for-third-party-dependencies |
It supports |
We are also missing a global option |
Closing as per above |
AFAIK, while the configure options are named |
Checked the docs and indeed it's documented as:
this is quite confusing but you are right 👍 In any case we are still missing global options for all of them |
This patch adds a new configure option --with-relative-rpath that, when
enabled, adds $ORIGIN-based RPATHs to binaries when building Python on Linux.
This makes Python installations relocatable so they can be moved to different
directories without breaking dynamic library dependencies.
Three new variables are introduced to set RPATHs for different components:
This is a step toward solving the relocatability issues